import { StyleSheet, Platform, Alert } from 'react-native';

import screen from './screen';

const { EW, EH } = screen;
// Alert.alert(JSON.stringify(screen.EW));
export function create(styles) {
  const platformStyles = {};

  Object.keys(styles).forEach(name => {
    let { ios, android, ...style } = { ...styles[name] };
    if (ios && Platform.OS === 'ios') {
      style = { ...style, ...ios };
    }
    if (android && Platform.OS === 'android') {
      style = { ...style, ...android };
    }
    platformStyles[name] = style;

    const width = platformStyles[name].width;
    const height = platformStyles[name].height;
    const fontSize = platformStyles[name].fontSize;
    const marginTop = platformStyles[name].marginTop;
    const marginBottom = platformStyles[name].marginBottom;
    const marginLeft = platformStyles[name].marginLeft;
    const marginRight = platformStyles[name].marginRight;
    const paddingTop = platformStyles[name].paddingTop;
    const paddingBottom = platformStyles[name].paddingBottom;
    const paddingLeft = platformStyles[name].paddingLeft;
    const paddingRight = platformStyles[name].paddingRight;
    const paddingHorizontal = platformStyles[name].paddingHorizontal;
    const paddingVertical = platformStyles[name].paddingVertical;
    const top = platformStyles[name].top;
    const bottom = platformStyles[name].bottom;
    const right = platformStyles[name].right;
    const left = platformStyles[name].paddingVertical;
    if (width && typeof width === 'number') {
      platformStyles[name].width = width * EW;
    }
    if (height && typeof height === 'number') {
      platformStyles[name].height = height * EH;
    }
    if (marginTop && typeof marginTop === 'number') {
      platformStyles[name].marginTop = marginTop * EH;
    }
    if (marginBottom && typeof marginBottom === 'number') {
      platformStyles[name].marginBottom = marginBottom * EH;
    }
    if (fontSize && typeof fontSize === 'number') {
      platformStyles[name].fontSize = fontSize * EW;
    }
    if (marginLeft && typeof marginLeft === 'number') {
      platformStyles[name].marginLeft = marginLeft * EW;
    }
    if (marginRight && typeof marginRight === 'number') {
      platformStyles[name].marginRight = marginRight * EW;
    }
    if (paddingTop && typeof paddingTop === 'number') {
      platformStyles[name].paddingTop = paddingTop * EH;
    }
    if (paddingBottom && typeof paddingBottom === 'number') {
      platformStyles[name].paddingBottom = paddingBottom * EH;
    }
    if (paddingLeft && typeof paddingLeft === 'number') {
      platformStyles[name].paddingLeft = paddingLeft * EW;
    }
    if (paddingRight && typeof paddingRight === 'number') {
      platformStyles[name].paddingRight = paddingRight * EW;
    }
    if (paddingHorizontal && typeof paddingHorizontal === 'number') {
      platformStyles[name].paddingHorizontal = paddingHorizontal * EW;
    }
    if (paddingVertical && typeof paddingVertical === 'number') {
      platformStyles[name].paddingVertical = paddingVertical * EH;
    }
    if (left && typeof left === 'number') {
      platformStyles[name].left = left * EW;
    }
    if (right && typeof right === 'number') {
      platformStyles[name].right = right * EW;
    }
    if (bottom && typeof bottom === 'number') {
      platformStyles[name].bottom = bottom * EH;
    }
    if (top && typeof top === 'number') {
      platformStyles[name].top = top * EH;
    }
  });
  return StyleSheet.create(platformStyles);
}
